const express = require('express');
//创建路由
const route = express.Router()
const adminModel = require('../db/model/adminModel')
const isLoginMiddle = require('../middleware/isLoginMiddle');
route.delete('/deleteAdmin',isLoginMiddle,async (req, res) => {
    const {
        adminName
    } = req.query
    console.log("请求删除"+adminName);
    try {
        //adminModel。deleteOne会返回删除的个数，当不为0时表示删除成功
        const deleteResult = await adminModel.deleteOne({
            adminName
        })
        //拿返回值与0做判断，成立则表示删除成功
        if(deleteResult.deletedCount>0){
            return res.send({
                code: 10000,
                msg:  "删除管理员" + adminName + "成功",
                data: null
            })
        }
        res.send({
            code: 10001,
            msg:  "删除管理员" + adminName + "失败",
            data: null
        })
       
    } catch (e) {
        console.log("删除管理员列表异常" + e.message);
        res.send({
            code: 10001,
            msg: "删除管理员异常" + e.message,
            data: null
        })
    }
})
module.exports = route;